<template>
  <!-- 论文发表 -->
  <el-dialog
    :title="title"
    :visible.sync="openDlg"
    v-if="openDlg"
    width="50%"
    append-to-body
    destroy-on-close
  >
    <el-form ref="form" :model="form" label-width="130px">
      <el-row>
        <el-col :span="12">
          <el-form-item label="姓名:">
            {{ form.applyName }}
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="所在部门:">
            {{ form.parameter.collegeName }}
          </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="成果名称:" prop="resultName">
              {{ form.parameter.resultName }}
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="成果形式:" prop="resultForm">
              {{ form.parameter.resultForm }}
              <!-- <el-select
                v-model="form.resultForm"
                placeholder="请选择"
                style="width: 100%"
              >
                <el-option
                  v-for="dict in dict.type.clr_result_form"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select> -->
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="论文类型:" prop="pubType">
              {{ form.parameter.pubType }}
              <!-- <el-select
                v-model="form.pubType"
                placeholder="请选择"
                style="width: 100%"
              >
                <el-option
                  v-for="dict in dict.type.clr_pub_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select> -->
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="发表时间:" prop="pubDate">
              {{ form.parameter.pubDate }}
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="发表网站:" prop="pubWebsite">
              {{ form.parameter.pubWebsite }}
              <!-- <el-select
                v-model="form.pubWebsite"
                placeholder="请选择"
                style="width: 100%"
              >
                <el-option
                  v-for="dict in dict.type.clr_pub_website"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select> -->
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="备注:" prop="certNumber">
              {{ form.parameter.certNumber }}
            </el-form-item>
          </el-col>
        <el-col :span="12">
          <el-form-item label="附件:" prop="attachment">
            <el-button
              size="mini"
              type="text"
              @click="handleExports(form.parameter.attachment)"
              >下载附件</el-button
            >
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">通 过</el-button>
      <el-button  @click="refusal">拒 绝</el-button>
    </div>
  </el-dialog>
</template>
          
          <script>
          import { getDicts } from "@/api/system/dict/type";

export default {
  name: "thesis",

  dicts: [
    "clr_topic_category", // 获奖类型
    "clr_topic_level",
  ],
  data() {
    return {
      title: "",
      openDlg: false,
      // 表单参数
      form: {},

      queryParams: {
        pageNum: 1,
        pageSize: 200,
        deptId: "",
        selectedObject: null,
      },
      userNum: 0,
      moneyNum: 0,

      yearStr: "",

      hasTypes: [],
      dlgType: "add",
      counselorList: [],
    };
  },
  watch: {},
  methods: {
    open(type, rowdata) {
      this.dlgType = type;
      this.form = {};
      if (type == "add") {
        this.title = "新增";
        this.form = {};
      } else {
        this.title = "查看详情";
        console.log(typeof rowdata.parameter, "传递的参数");
        this.form = rowdata;
        if(typeof rowdata.parameter == 'object'){
          this.form = rowdata;
        }else{
          this.form.parameter = JSON.parse(rowdata.parameter);
        }
        getDicts("clr_result_form").then(res => {
                    res.data.forEach(e => {
                        if (this.form.parameter.resultForm == e.dictValue) {
                            this.form.parameter.resultForm = e.dictLabel
                        }
                    })
                });
        getDicts("clr_pub_type").then(res => {
                    res.data.forEach(e => {
                        if (this.form.parameter.pubType == e.dictValue) {
                            this.form.parameter.pubType = e.dictLabel
                        }
                    })
                });
        getDicts("clr_pub_website").then(res => {
                    res.data.forEach(e => {
                        if (this.form.parameter.pubWebsite == e.dictValue) {
                            this.form.parameter.pubWebsite = e.dictLabel
                        }
                    })
                });

        console.log(this.form, "传递的参数");
      }
      this.openDlg = true;
    },
    handleExports(row) {
      let link = document.createElement("a");
      //创建一个a标签
      link.style.display = "none";
      //将a标签隐藏
      link.href = process.env.VUE_APP_BASE_API + row;
      //给a标签添加下载链接  "域名+接口"  safe是一个动态的域名  后面的接口替换成你自己的下载接口
      link.setAttribute(
        "download",
        this.form.applyName + "课题申请"
      );
      // 此处注意，要给a标签添加一个download属性，属性值就是文件名称 否则下载出来的文件是没有属性的，空白白
      document.body.appendChild(link);
      //将上面创建的a标签加入到body的尾部
      link.click();
      // 执行a标签
    },
    submitForm() {
      this.$emit("onSearch", this.form);
      this.openDlg = false;
    },
    refusal() {
      this.$emit("refuse",this.form);
        this.openDlg = false;
    }
  },
};
</script>
          
          <style lang="scss" scoped>
.planTotal {
  display: flex;
  font-size: 13px;
  color: #606266;
  &-left {
    margin-left: 30px;
  }
  &-right {
    margin-left: 20px;
  }
}
</style>